fetch("http://101.200.226.244:3000/song/detail"+location.search,{
    method:"get",
    mode:"cors"
}).then(r=>r.json())
.then(data=>{
    console.log(data)
    $(".song_lyric>h3").innerText=data.songs[0].name;
    $(".bg>img").setAttribute("src",data.songs[0].al.picUrl);
    $(".circle>img").setAttribute("src",data.songs[0].al.picUrl);
    
    fetch("http://101.200.226.244:3000/song/url?id="+data.songs[0].id,{
        method:"get",
        mode:"cors"
    }).then(r=>r.json())
    .then(song_data=>{
        console.log(song_data)
        audio.setAttribute("src",song_data.data[0].url)

        fetch("http://101.200.226.244:3000/lyric?id="+data.songs[0].id,{
            method:"get",
            mode:"cors"
        }).then(r=>r.json())
        .then(lyric_data=>{
            console.log(lyric_data)

            let lyric = new window.Lyric(lyric_data.lrc.lyric, function (obj) {
                // document.getElementById('lrc').innerText =obj.txt
                $(".song_lyric>p").innerText=obj.txt
                console.log(obj)
              })
              
              
            let num=1;
            $("#audio").onloadedmetadata=function(){
                console.log("加载完成")

                $("#customRange1").oninput=function(){
                    //当前value*duration/100
                    //this指代事件的发起者
                    $("#audio").currentTime=this.value/100*$("#audio").duration;
                    //console.log(this.value)
                    //console.log($("#audio").duration/100)
                    lyric.seek(this.value/100*$("#audio").duration*1000)
                    // lyric.togglePlay()
                    //console.log(lyric)

                }


                $(".circle>img").onclick=function(){
                    num++;
                    console.log(num)
                    if( num%2==0){
                        $("#audio").play();
                        
                        $(".circle>img").classList.remove('stop')
                        $(".circle>img").classList.add('move')
                        lyric.togglePlay()
                        

                        //歌曲总时长                                       
                        console.log($('#audio').duration)
                        // $('#audio').duration
                        $('#audio').ontimeupdate=function(){
                            // console.log($('#audio').currentTime*100)
                        $('#customRange1').value=$('#audio').currentTime*100/$('#audio').duration
                        }
                    }else{
                        $("#audio").pause();
                         //$(".circle>img").classList.add('move')
                        $(".circle>img").classList.add('stop')
                        lyric.togglePlay()
                    }
                }
            }
        })
    })
})